package cn.fl.customer.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstMidManInfoService;
import cn.fl.customer.transform.CstMidManInfoVOTransform;
import cn.fl.customer.vo.CstMidManInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import fl.customer.facade.customer.api.ICustomerApiService;
import fl.customer.facade.customer.dto.CstMidManInfoDTO;

/**
 * @Description: 客户中间人信息表 客户端服务层接口实现
 * @Description: 持久层方法名称前缀：新增：insert* 删除：delete* 修改：update* 批量：batch* 查询对象：select* get* find* 查询集合：select*
 */
@Service
@SuppressWarnings("unchecked")
public class CstMidManInfoServiceImpl implements ICstMidManInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(ICstMidManInfoService.class);
	
	/**
	 * 客户API服务
	 */
	@Autowired
	private ICustomerApiService customerApiService;

	@Override
	public CstMidManInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		CstMidManInfoDTO dto = this.customerApiService.selectCstMidManInfoById(id);
		return CstMidManInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(CstMidManInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.customerApiService.addCstMidManInfo(CstMidManInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		List<Long> ids = new ArrayList<>();
		ids.add(id);
		return this.customerApiService.removeCstMidManInfoByIds(ids);
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return this.customerApiService.removeCstMidManInfoByIds(ids);
    }

	@Override
	public boolean modify(CstMidManInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.customerApiService.modifyCstMidManInfo(CstMidManInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		page = this.customerApiService.searchCstMidManInfoPage(page);
		List<CstMidManInfoDTO> dtoList = (List<CstMidManInfoDTO>)page.getResultList();
		page.setResultList(CstMidManInfoVOTransform.toVOList(dtoList));
		return page;
	}
}
